<template>
  <div>
    <operation-title
      title="标题栏"
      :icon="TitleIcon"
    />
    <div class="divider" />
    <div class="func">
      <p class="attr">
        选择风格
      </p>
      <div class="adjust-item">
        <div
          class="style-btn"
          @click="dialogFormVisible = true"
        >
          修改风格
        </div>
        <span class="style-word">当前风格{{ config.pageConfig.style }}</span>
      </div>
    </div>
    <div class="divider" />
    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="func"
    >
      <p class="attr">
        图片
      </p>
      <div class="adjust-item">
        <span>启用</span>
        <el-radio-group v-model="config.pageConfig.pictureShow">
          <el-radio :label="true">
            是
          </el-radio>
          <el-radio :label="false">
            否
          </el-radio>
        </el-radio-group>
      </div>
      <div
        v-if="config.pageConfig.pictureShow"
        class="adjust-item"
      >
        <span>图片</span>
        <div class="img-placeholder">
          <div
            v-if="config.pageConfig.pictureUrl"
            class="upload-img"
          >
            <el-image
              style="width: 100%; height: 100%"
              :src="config.pageConfig.pictureUrl"
              fit="contain"
            />
            <div class="upload-img_cover">
              <Upload
                :model-value="picturefileList"
                file-path="actapp/"
                :limit="999"
                :show-file-list="false"
                @success="success"
              >
                <el-button size="small">
                  替换
                </el-button>
              </Upload>
            </div>
          </div>
          <Upload
            v-else
            v-model="config.pageConfig.pictureUrl"
            file-path="actapp/"
            list-type="picture-card"
          >
            <el-icon>
              <Plus />
            </el-icon>
          </Upload>
        </div>
        <h4 class="style-word">
          建议图片宽高80px*80px
        </h4>
      </div>
      <div
        v-if="config.pageConfig.pictureShow"
        class="adjust-item"
      >
        <span>圆角</span>
        <el-slider
          v-model="config.pageConfig.radius"
          :min="0"
          :max="20"
          show-input
          size="small"
        />px
      </div>
    </div>
    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="divider"
    />
    <div
      v-if="['2', '3', '4'].includes(config.pageConfig.style)"
      class="func"
    >
      <p class="attr">
        主标题
      </p>
      <div class="adjust-item">
        <span>颜色</span>
        <el-color-picker v-model="config.pageConfig.textcolor" />
        <span>{{ config.pageConfig.textcolor }}</span>
      </div>
      <div class="adjust-item">
        <span>字号</span>
        <el-slider
          v-model="config.pageConfig.fontsize"
          :min="14"
          :max="20"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>其他</span>
        <el-checkbox
          v-model="config.pageConfig.fontbold"
          label="加粗"
          size="large"
        />
        <el-checkbox
          v-model="config.pageConfig.fontstyle"
          label="倾斜"
          size="large"
        />
      </div>
      <div class="adjust-item">
        <span>内容</span>
        <el-input
          v-model="config.pageConfig.title"
          maxlength="20"
          :show-word-limit="true"
        />
      </div>
    </div>
    <div
      v-if="['2', '3', '4'].includes(config.pageConfig.style)"
      class="divider"
    />
    <div
      v-if="['2', '3', '4'].includes(config.pageConfig.style)"
      class="func"
    >
      <p class="attr">
        子标题
      </p>
      <div class="adjust-item">
        <span>启用</span>
        <el-radio-group v-model="config.pageConfig.subTitleShow">
          <el-radio :label="true">
            是
          </el-radio>
          <el-radio :label="false">
            否
          </el-radio>
        </el-radio-group>
      </div>
      <div class="adjust-item">
        <span>颜色</span>
        <el-color-picker v-model="config.pageConfig.subTitlecolor" />
        <span>{{ config.pageConfig.subTitlecolor }}</span>
      </div>
      <div class="adjust-item">
        <span>字号</span>
        <el-slider
          v-model="config.pageConfig.subFontsize"
          :min="12"
          :max="15"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>内容</span>
        <el-input
          v-model="config.pageConfig.subcontent"
          maxlength="20"
          :show-word-limit="true"
        />
      </div>
    </div>
    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="divider"
    />

    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="func"
    >
      <p class="attr">
        “更多”按钮设置
      </p>
      <div class="adjust-item">
        <span>启用</span>
        <el-radio-group v-model="config.pageConfig.moreShow">
          <el-radio :label="true">
            是
          </el-radio>
          <el-radio :label="false">
            否
          </el-radio>
        </el-radio-group>
      </div>
      <div class="adjust-item">
        <span>箭头</span>
        <el-radio-group v-model="config.pageConfig.arrowShow">
          <el-radio :label="true">
            是
          </el-radio>
          <el-radio :label="false">
            否
          </el-radio>
        </el-radio-group>
      </div>
      <div class="adjust-item">
        <span>颜色</span>
        <el-color-picker v-model="config.pageConfig.morecolor" />
        <span>{{ config.pageConfig.morecolor }}</span>
      </div>
      <div class="adjust-item">
        <span>内容</span>
        <el-input
          v-model="config.pageConfig.morecontent"
          maxlength="4"
          :show-word-limit="true"
        />
      </div>
      <div class="adjust-item">
        <span>链接</span>
        <el-input
          v-model="config.pageConfig.morelink"
          placeholder="请填写带有https/http的链接地址"
          clearable
          maxlength="200"
          :show-word-limit="true"
        />
      </div>
    </div>
    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="divider"
    />
    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="func"
    >
      <p class="attr">
        背景设置
      </p>
      <div class="adjust-item">
        <span>底部颜色</span>
        <el-color-picker v-model="config.pageConfig.color" />
        <span>{{ config.pageConfig.color }}</span>
      </div>
      <div class="adjust-item">
        <span>组件背景</span>
        <el-radio-group v-model="config.pageConfig.componentWay">
          <el-radio :label="1">
            背景色
          </el-radio>
          <el-radio :label="2">
            背景图片
          </el-radio>
        </el-radio-group>
      </div>
      <div
        v-if="config.pageConfig.componentWay == 1"
        class="adjust-item"
      >
        <el-color-picker v-model="config.pageConfig.componentcolor" />
        <span>{{ config.pageConfig.componentcolor }}</span>
      </div>
      <div
        v-if="config.pageConfig.componentWay == 2"
        class="adjust-item"
      >
        <div class="img-placeholder">
          <div
            v-if="config.pageConfig.componentUrl"
            class="upload-img"
          >
            <el-image
              style="width: 100%; height: 100%"
              :src="config.pageConfig.componentUrl"
              fit="contain"
            />
            <div class="upload-img_cover">
              <Upload
                :model-value="componentfileList"
                file-path="actapp/"
                :limit="999"
                :show-file-list="false"
                @success="componentsuccess"
              >
                <el-button size="small">
                  替换
                </el-button>
              </Upload>
            </div>
          </div>
          <Upload
            v-else
            v-model="config.pageConfig.componentUrl"
            file-path="actapp/"
            list-type="picture-card"
          >
            <el-icon>
              <Plus />
            </el-icon>
          </Upload>
        </div>
      </div>
    </div>
    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="divider"
    />
    <div
      v-if="['1', '5', '6', '7', '8'].includes(config.pageConfig.style)"
      class="func"
    >
      <p class="attr">
        标题文字
      </p>
      <div class="adjust-item">
        <span>文字</span>
        <el-input
          v-model="config.pageConfig.title"
          show-word-limit
          maxlength="20"
        />
      </div>
      <div class="adjust-item">
        <span>字号</span>
        <el-slider
          v-model="config.pageConfig.fontsize"
          :min="14"
          :max="20"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>其他</span>
        <el-checkbox
          v-model="config.pageConfig.fontbold"
          label="加粗"
          size="large"
        />
        <el-checkbox
          v-model="config.pageConfig.fontstyle"
          label="倾斜"
          size="large"
        />
      </div>
    </div>
    <div
      v-if="['2'].includes(config.pageConfig.style)"
      class="divider"
    />
    <div
      v-if="['1', '3', '4', '5', '6', '7', '8'].includes(config.pageConfig.style)"
      class="func"
    >
      <p class="attr">
        选择颜色
      </p>
      <div
        v-if="['1', '3', '4', '5', '6', '7', '8'].includes(config.pageConfig.style)"
        class="adjust-item"
      >
        <span>背景颜色</span>
        <el-color-picker v-model="config.pageConfig.color" />
        <span>{{ config.pageConfig.color }}</span>
      </div>
      <div
        v-if="['1', '5', '6', '7', '8'].includes(config.pageConfig.style)"
        class="adjust-item"
      >
        <span>标题颜色</span>
        <el-color-picker v-model="config.pageConfig.textcolor" />
        <span>{{ config.pageConfig.textcolor }}</span>
      </div>
    </div>
    <div class="divider" />
    <div class="func">
      <p class="attr">
        边距
      </p>
      <div class="adjust-item">
        <span>上边距</span>
        <el-slider
          v-model="config.pageConfig.marginTop"
          :min="0"
          :max="50"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>下边距</span>
        <el-slider
          v-model="config.pageConfig.marginBottom"
          :min="0"
          :max="50"
          show-input
          size="small"
        />px
      </div>
      <div class="adjust-item">
        <span>左右边距</span>
        <el-slider
          v-model="config.pageConfig.margin"
          :min="0"
          :max="20"
          show-input
          size="small"
        />px
      </div>
    </div>
    <div class="divider" />

    <el-dialog
      v-model="dialogFormVisible"
      class="dialog-form"
      title="选择图标"
      width="80%"
      :before-close="resetForm"
    >
      <div class="icon-div-container">
        <div
          v-for="(item, index) in styleList"
          :key="index"
          class="icon-div"
          @click="submitForm(item.id)"
        >
          <img :src="item.png">
        </div>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="resetForm()">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts">
export default {
  name: "TitleOperation",
};
</script>
<script lang="ts" setup>
import title1png from '@/assets/app/other/title/title1.png'
import title2png from '@/assets/app/other/title/title2.png'
import title3png from '@/assets/app/other/title/title3.png'
import title4png from '@/assets/app/other/title/title4.png'
import title5png from '@/assets/app/other/title/title5.png'
import title6png from '@/assets/app/other/title/title6.png'
import title7png from '@/assets/app/other/title/title7.png'
import title8png from '@/assets/app/other/title/title8.png'
import TitleIcon from "@/assets/app/icon/title.png";
import OperationTitle
  from "@/views/activity/actApp/components/default/operationComponents/operationTitle/OperationTitle.vue";
const config = defineProps({
  pageConfig: {
    type: Object,
    default: () => ({
      style: "1",
      color: "transparent",
      textcolor: "#333",
      title: "标题栏",
      marginTop: 0,
      marginBottom: 0,
      margin: 10,
      pictureShow: true,
      pictureUrl: "./imagesStatic/1663576769000Z8R8title-icon.png",
      radius: 0,
      fontsize: 16,
      fontbold: true,
      fontstyle: false,
      subTitleShow: true,
      subTitlecolor: '#b7bcd2',
      subFontsize: 12,
      subcontent: 'RECOMMEND',
      moreShow: true,
      arrowShow: true,
      morecolor: '#b0b3bf',
      morecontent: '查看更多',
      morelink: '',
      componentWay: 1,
      componentcolor: '#fff',
      componentUrl: '',
    }),
  },
});
let index = 0;
const styleList = ref([{ id: '1', png: title1png }, { id: '2', png: title2png }, { id: '3', png: title3png }, { id: '4', png: title4png }, { id: '5', png: title5png }, { id: '6', png: title6png }, { id: '7', png: title7png }, { id: '8', png: title8png }])
const currentIndex = ref(999);
let emits = defineEmits<{ (e: "changeStyle", configStyle: Object): void }>();
const dialogFormVisible = ref(false);
const resetForm = () => {
  dialogFormVisible.value = false;
};
const showDialog = (idx: number) => {
  index = idx;
  dialogFormVisible.value = true;
};
const submitForm = (item: number) => {
  config.pageConfig.style = item;
  dialogFormVisible.value = false;
};
const picturefileList = ref([]);
const success = (value: any) => {
  config.pageConfig.pictureUrl = value.url;
};
const componentfileList = ref([]);
const componentsuccess = (value: any) => {
  config.pageConfig.componentUrl = value.url;
};
watch(config, (val) => {
  emits("changeStyle", config.pageConfig);
});
</script>

<style lang="scss" scoped>
.title {
  padding: 8px 23px;
  overflow: hidden;
  border-bottom: 5px solid #f6f7f9;
  display: flex;
  position: relative;
  height: 50px;
  box-sizing: border-box;

  img {
    position: absolute;
    left: 0;
    top: -5px;
  }

  h5 {
    font-size: 16px;
    font-weight: 700;
    position: absolute;
    left: 70px;
    top: 0;
    line-height: 50px;
  }
}

.func {
  border-bottom: 5px solid #f6f7f9;
  padding: 20px 16px;
  font-size: 16px;

  .attr {
    line-height: 1;
    color: #47565d;
    font-weight: bolder;
    margin-bottom: 20px;
  }

  ul.common-ul {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;

    li {
      flex: 1;
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px 0 0 4px;
      border: 1px solid #ededed;
      border-collapse: collapse;

      &.active {
        border: 1px solid #fb6638;
      }

      img {
        max-width: 100% !important;
        max-height: 100% !important;
      }
    }
  }

  h4 {
    position: relative;
    padding: 8px 16px 8px 16px;
    border-radius: 6px;
    color: #666;
    font-size: 12px;
    line-height: 22px;
    margin-bottom: 10px;
    border: 1px solid #d8e8fc;
    background-color: #e5f0fe;
  }

  div.adjust-item {
    display: flex;
    align-items: center;
    margin-top: 3px;
    margin-bottom: 10px;

    .style-btn {
      width: 240px;
      height: 36px;
      font-size: 12px;
      line-height: 36px;
      text-align: center;
      background-color: #001E70;
      color: #fff;
      margin-right: 5px;
    }

    .style-word {
      font-size: 12px;
    }

    span {
      width: 64px;
      text-align: right;
      margin-right: 15px;
      color: #666;
    }

    :deep(.el-slider) {
      width: 240px;
      margin-right: 3px;
      margin-left: 15px;
    }

    :deep(.el-slider__runway.show-input) {
      margin-right: 15px;
    }

    :deep(.el-input-number) {
      width: 100px;
      background: #f4f3f7;
      border: 1px solid #f4f3f7;
    }
  }

  .add-item {
    width: 100%;
    list-style: none;

    li {
      background: #f4f3f7;
      border-radius: 4px;
      padding: 10px 20px 10px 10px;
      color: #999;
      margin-top: 10px;
      margin-bottom: 20px;
      position: relative;

      .add-item-input {
        display: flex;
        align-items: center;
        margin-bottom: 20px;

        >p {
          width: 50px;
          margin-right: 10px;
        }

        > :deep(.el-icon) {
          font-size: 40px;
        }

        img {
          width: 40px;
          height: 40px;
        }

        :deep(.el-color-picker) {
          margin-right: 10px;
        }
      }

      .sure-close {
        position: absolute;
        right: 5px;
        top: 5px;
        cursor: pointer;
      }
    }

    .extra-li {
      text-align: center;
    }
  }
}

.icon-div-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;

  .icon-div {
    width: calc(33.3% - 40px);
    margin: 12px;
    border: 1px solid #ededed;
    background: #f7f8fa;

    img {
      display: block;
      max-width: 100%;
      max-height: 100%;
    }
  }

}

.img-placeholder {
  width: 80px;
  height: 80px;
  margin-right: 10px;
  margin-bottom: 10px;
}

.upload-img {
  width: 80px;
  height: 80px;
  line-height: 80px;
  margin-right: 10px;
  border: 1px dashed #ededed;
  text-align: center;
  color: #dad9d9;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  float: left;
  position: relative;

  :deep(.el-image) {
    width: 80px;
    height: 80px;
  }

  &:hover {
    .upload-img_cover {
      opacity: 1;
    }
  }

  .upload-img_cover {
    opacity: 0;
    position: absolute;
    transition: all 0.3s ease;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
  }
}

:deep(.el-upload-list) {
  width: 80px;
  height: 80px;
  margin-right: 10px;
}

:deep(.el-upload--picture-card) {
  width: 80px;
  height: 80px;
}
</style>
